<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import BScroll from '@better-scroll/core'
  import Pullup from '@better-scroll/pull-up'
  import ObserveDOM from '@better-scroll/observe-dom'
  import ObserveImage from '@better-scroll/observe-image'
  BScroll.use(ObserveImage)
  BScroll.use(Pullup)
  BScroll.use(ObserveDOM)
  export default {
    props:{
      probetype:{
        type:Number,
        default:0
      },
      pullUpLoad:{
        type:Boolean,
        default:false
      },
      startY:{
        type:Number,
        default:0
      }
    },
    data() {
      return {
        bs: null
      }
    },
    methods: {
      backtop(x, y, time = 300) {
        this.bs.scrollTo(x, y, time)
        // console.log("触发",y);
      },
      backscoll(x, y, time = 0) {
        this.bs.scrollTo(x, y, time)
        // console.log("前往:",y);
      },
      finishUpLoad(){
        this.bs.finishPullUp()
      },
      refreshLoad(){
        this.bs.refresh()
      },
			getScrollY() {
				return this.bs.y
			},
			// gotoel(el){
			// 	this.bs.scrollToElement(el,200,0,0)
			// }
    },
    mounted() {
      this.bs = new BScroll(this.$refs.wrapper, {
        probeType: this.probetype,
        scrollY: true,
        click: true,
        startY:this.startY,
        observeDOM: true,
        pullUpLoad: this.pullUpLoad,
        observeImage: true
      })
	  
      // 监听滚动事件,
	  if(this.probetype==2 || this.probetype==3){
		  this.bs.on('scroll', (options) => {
		    this.$emit('scrollY', options)
		  })
	  }

      // 监听滚动触底事件,
	  if(this.pullUpLoad){
		  this.bs.on('pullingUp', () => {
		  		  // 监听到滚动到底部
		    this.$emit('pullingup')
		  })
	  }
    }
  }
</script>

<style>
</style>
